package cn.yuhh.core.util;

import org.apache.commons.codec.binary.Base64;

import java.io.UnsupportedEncodingException;


public class DigestUtils {

    public final static String ENCODING = "UTF-8";

    public static String MD5(String data) {
        return org.apache.commons.codec.digest.DigestUtils.md5Hex(data);
    }


    public static String encodeBase64(byte[] date) {
        try {
            return new String(Base64.encodeBase64(date), ENCODING);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("encoding unknow", e);
        }
    }

    public static byte[] decodeBase64(byte[] date) {

        return Base64.decodeBase64(date);
    }
}
